package com.example.controller;


import com.example.entity.Article;
import com.example.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

//Controller 用于直接访问界面
//@Controller

//restController用于访问caching缓存
@RestController
//@RequestMapping("/admin")
public class ArticleController {

    @Autowired
    ArticleService articleService;

    @GetMapping("/article")
    public String article(Model model) {

        List<Article> articleList = articleService.findAll();

        model.addAttribute("articles", articleList);

        return "article";
    }


    @GetMapping("/article/{id}")
    public Article findArticle(@PathVariable("id") Integer id) {
        return articleService.findArticleById(id);
    }


//    @GetMapping("article/{id}/{content}")
//    public Article updateArticle(@PathVariable("id") Integer id,@PathVariable("content") String content){
//
//    }
}
